package com.panwenliang2008.eatwhat.data.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.panwenliang2008.eatwhat.data.entity.Food

@Dao
interface FoodDao {
    @Query("SELECT * FROM food")
    fun getAll(): LiveData<List<Food>>

    @Query("SELECT * FROM food WHERE food_id NOT IN (:foodId) ORDER BY RANDOM() LIMIT 1")
    fun getRandomFood(foodId: Int): LiveData<Food>

    @Query("SELECT * FROM food WHERE food_id = :foodId")
    fun loadById(foodId: Int): Food

    @Query("SELECT * FROM food WHERE food_id IN (:userIds)")
    fun loadAllByIds(userIds: IntArray): List<Food>

    @Query("SELECT * FROM food WHERE food_name LIKE :food LIMIT 1")
    fun findByName(food: String): Food

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(foods: List<Food>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(food: Food)

    @Delete
    suspend fun delete(food: Food)
}